package com.jack.leetcode.eachProblem08;

public class 数字范围按位与 {

    public static void main(String[] args) {
        System.out.println(rangeBitwiseAnd(5, 7));
    }

    public static int rangeBitwiseAnd(int m, int n) {
        int mask = 1 << 30;
        int result = 0;
        while (mask > 0 && (m & mask) == (n & mask)) {
            result |= (m & mask);
            mask >>= 1;
        }
        return result;
    }
}
